/*!
 * @file velocity_publisher.cpp
 * @brief 该例程发布turtle1/cmd_vel话题，消息类型geometyr_msgs::Twist
 * @author FanKaiyu
 * @version 0.0.1
 * @date 2022-03-16
 */
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>

int main(int argc, const char** argv) {
    // ROS节点初始化
    ros::init(argc,const_cast<char**>(argv),"velocity_publisher");

    // 创建节点句柄
    ros::NodeHandle n;

    // 创建1个Publisher, 发布名为/turtle1/cmd_vel的topic, 消息类型为geometry_msgs::Twist, 队列长度10
    ros::Publisher turtle_vel_pub = n.advertise<geometry_msgs::Twist>("/turtle1/cmd_vel", 10);

    // 设置循环的要素
    ros::Rate loop_rate(10);

    int count = 0;
    while (ros::ok())
    {
        // 初始化gepmetry_msgs::Twist类型的消息
        geometry_msgs::Twist vel_msg;
        vel_msg.linear.x = 0.5;
        vel_msg.angular.z = 0.2;

        // 发布消息
        turtle_vel_pub.publish(vel_msg);
        ROS_INFO("Publish turtle velocity command(%0.2f m/s, %0.2f rad/s)",vel_msg.linear.x, vel_msg.angular.z);

        // 按照循环频率延时
        loop_rate.sleep();
    }
    
    return 0;
}